package com.fengli.task.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;

import javax.persistence.*;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.sql.Date;
import java.sql.Timestamp;
import java.util.Objects;

/**
 * @Description:
 * @Author: fengli
 * @Date 4/23/19 2:06 PM
 */
@Entity
@Table(name = "task", schema = "task", catalog = "")
public class TaskEntity {
    private String id;

    @Min(value = 0, message = "重要性只能大于等于0，小于等于100")
    @Max(value = 100, message = "重要性只能大于等于0，小于等于100")
    private Integer importanceValue;
    @NotNull(message = "任务内容不能为空!")
    private String content;
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date date;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Timestamp createTime;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Timestamp startTime;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Timestamp endTime;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Timestamp realEndTime;
    private Boolean isDone=false;
    private Boolean del=false;

    //这个外键，是手动加入的
    private String userId;

    @Id
    @Column(name = "id")
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Basic
    @Column(name = "importance_value")
    public Integer getImportanceValue() {
        return importanceValue;
    }

    public void setImportanceValue(Integer importanceValue) {
        this.importanceValue = importanceValue;
    }

    @Basic
    @Column(name = "content")
    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Basic
    @Column(name = "date")
    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    @Basic
    @Column(name = "create_time")
    public Timestamp getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Timestamp createTime) {
        this.createTime = createTime;
    }

    @Basic
    @Column(name = "start_time")
    public Timestamp getStartTime() {
        return startTime;
    }

    public void setStartTime(Timestamp startTime) {
        this.startTime = startTime;
    }

    @Basic
    @Column(name = "end_time")
    public Timestamp getEndTime() {
        return endTime;
    }

    public void setEndTime(Timestamp endTime) {
        this.endTime = endTime;
    }

    @Basic
    @Column(name = "real_end_time")
    public Timestamp getRealEndTime() {
        return realEndTime;
    }

    public void setRealEndTime(Timestamp realEndTime) {
        this.realEndTime = realEndTime;
    }

    @Basic
    @Column(name = "is_done")
    @JsonProperty("isDone")
    public boolean isDone() {
        return isDone;
    }

    public void setDone(boolean done) {
        isDone = done;
    }

    @Basic
    @Column(name = "del")
    public boolean isDel() {
        return del;
    }

    public void setDel(boolean del) {
        this.del = del;
    }


    @Column(name = "user_id")
    public String getUserId() {
        return userId;
    }

    public void setUserId(String user_id) {
        this.userId = user_id;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        TaskEntity that = (TaskEntity) o;
        return isDone == that.isDone &&
                del == that.del &&
                Objects.equals(id, that.id) &&
                Objects.equals(importanceValue, that.importanceValue) &&
                Objects.equals(content, that.content) &&
                Objects.equals(date, that.date) &&
                Objects.equals(createTime, that.createTime) &&
                Objects.equals(startTime, that.startTime) &&
                Objects.equals(endTime, that.endTime) &&
                Objects.equals(realEndTime, that.realEndTime) &&
                Objects.equals(userId,that.userId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, importanceValue, content, date, createTime, startTime, endTime, realEndTime, isDone, del,userId);
    }

    @Override
    public String toString() {
        return "TaskEntity{" +
                "id='" + id + '\'' +
                ", importanceValue=" + importanceValue +
                ", content='" + content + '\'' +
                ", date=" + date +
                ", createTime=" + createTime +
                ", startTime=" + startTime +
                ", endTime=" + endTime +
                ", realEndTime=" + realEndTime +
                ", isDone=" + isDone +
                ", del=" + del +
                ", userId=" + userId +
                '}';
    }
}
